package py.cursoweb.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ListadoProductos extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListadoProductos() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		procesarPeticion(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		procesarPeticion(request, response);
	}

	protected void procesarPeticion(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		//String operacion = request.getParameter("operacion");
		ProductoManager manager = new ProductoManager();
		//ProveedorManager provManager = new ProveedorManager();
				
		//if ("todos".equals(operacion)) {
			//mostrar lista de todos los alumnos
			try {
				request.setAttribute("listaProductos", manager.getProductos());
				//request.setAttribute("listaProveedoresProd", provManager.getProveedores());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			llamarPagina(request,response,"/jsp/listaProductos.jsp");
		//}
	}
	
	protected void llamarPagina(HttpServletRequest request, HttpServletResponse response, String page) throws ServletException, IOException {
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);
		dispatcher.forward(request,response);		
	}

}
